﻿<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">搜索：</label>
                        <div class="layui-input-inline mr0">
                            <input name="keyword" class="layui-input" type="text" placeholder="输入关键字"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn icon-btn" lay-filter="formSubSearchBizLayerGroup" lay-submit>
                            <i class="layui-icon">&#xe615;</i>搜索
                        </button>
                        <button id="btnAddBizLayerGroup" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                    </div>
                </div>
            </div>

            <table class="layui-table" id="tableBizLayerGroup" lay-filter="tableBizLayerGroup"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="tableBarBizLayerGroup">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!-- 表单弹窗 -->
<script type="text/html" id="modelBizLayerGroup">
    <form id="modelBizLayerGroupForm" lay-filter="modelBizLayerGroupForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
                <input name="name" placeholder="请输入名称" type="text" class="layui-input" maxlength="50"
                       lay-verType="tips" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">标识</label>
            <div class="layui-input-block">
                <input name="code" placeholder="请输入标识" type="text" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">序号</label>
            <div class="layui-input-block">
                <input name="sort" placeholder="请输入序号" type="number" class="layui-input" min="0" max="1000"
                       lay-verType="tips" lay-verify="required|number" required/>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="modelSubmitBizLayerGroup" lay-submit>保存</button>
        </div>
    </form>
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="modelBizLayerGroupData">
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-table" id="tableBizLayerGroupData" lay-filter="tableBizLayerGroupData"></table>
        </div>
    </div>
</script>
<!-- 表格操作列 -->
<script type="text/html" id="tableBarBizLayerGroupData">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="authData">授权</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="cancelData">取消</a>
</script>





<!-- js部分 -->
<script>
layui.extend({
    treeSelect: '/treeSelect/treeSelect'
}).use(['layer', 'form', 'table', 'util', 'admin', 'zTree','treetable', 'config','treeSelect'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var config = layui.config;
        var treetable = layui.treetable;
        var treeSelect=layui.treeSelect;
        var config = layui.config;
        // 渲染表格
        var insTb = table.render({
            elem: '#tableBizLayerGroup',
            url: '#(ctx)/biz/layer/group/listData',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers'},
                {field: 'name', sort: true, title: '名称'},
                {field: 'code', sort: true, title: '标识'},
                {align: 'center', toolbar: '#tableBarBizLayerGroup', title: '操作', minWidth: 150}
            ]]
        });

        // 添加
        $('#btnAddBizLayerGroup').click(function () {
            showEditModel();
        });

        // 搜索
        form.on('submit(formSubSearchBizLayerGroup)', function (data) {
            insTb.reload({where: data.field}, 'data');
        });

        // 工具条点击事件
        table.on('tool(tableBizLayerGroup)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'edit') { // 修改
                showEditModel(data);
            } else if (layEvent === 'del') { // 删除
                doDel(obj);
            }
            
        });

        // 删除
        function doDel(obj) {
        	layer.confirm('确定要删除“【<span style="color:red;">' +obj.data.name+ '</span>】”吗？', {
                skin: 'layui-layer-admin',
                shade: .1
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('biz/layer/group/delete', {
                    id: obj.data.id
                }, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.message, {icon: 1});
                        insTb.reload({}, 'data');
                    } else {
                        layer.msg(res.message, {icon: 2});
                    }
                }, 'get');
            });
        }

        // 显示编辑弹窗
        function showEditModel(mBizLayerGroup) {
            admin.open({
                type: 1,
                title: (mBizLayerGroup ? '编辑' : '添加') ,
                content: $('#modelBizLayerGroup').html(),
                success: function (layero, dIndex) {
                    var url = 'biz/layer/group/save';
                    form.val('modelBizLayerGroupForm', mBizLayerGroup);  // 回显数据
                    // 表单提交事件
                    form.on('submit(modelSubmitBizLayerGroup)', function (data) {
                        layer.load(2);
                        var formData={}; 
                        for(var key in data.field){
                        	formData['bizLayerGroup.'+key]=data.field[key];
                        }
                        admin.req(url, formData, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.close(dIndex);
                                layer.msg(res.message, {icon: 1});
                                insTb.reload({}, 'data');
                            } else {
                                layer.msg(res.message, {icon: 2});
                            }
                        }, 'get');
                        return false;
                    });
                }
            });
        }


        

        
        
    });
</script>